﻿using HR.Config;
using HR.IService;
using HR.Models;

namespace HR.Service
{
    public class First_kindService:IFirst_kindService
    {
        private readonly IConfiguration configuration;
        private readonly HRDBContext db;

        public First_kindService(IConfiguration configuration,HRDBContext db)
        {
            this.configuration = configuration;
            this.db = db;
        }

        public Task<int> AddFirstKind(config_file_first_kind ffk)
        {
            return Task.Run(() =>
            {
                db.config_file_first_kinds.Add(ffk);
                return db.SaveChanges();
            });
        }

        public async Task<Paging<config_file_first_kind>> FirstKindPage()
        {
            return await Task.Run(() =>
            {
                List<config_file_first_kind> cffk = db.config_file_first_kinds.ToList();
                Paging<config_file_first_kind> pg = new Paging<config_file_first_kind>()
                {
                    rows = cffk.Count,
                    tabs = cffk
                };
                return pg;
            });
        }

        public Task<int> UdpFirstKind(config_file_first_kind ffk)
        {
            return Task.Run(() =>
            {
                config_file_first_kind? fk = db.config_file_first_kinds.Find(ffk.ffk_id);
                fk.first_kind_id = ffk.first_kind_id;
                fk.first_kind_name = ffk.first_kind_name;
                fk.first_kind_sale_id = ffk.first_kind_sale_id;
                fk.first_kind_salary_id = ffk.first_kind_salary_id;
                int res = db.SaveChanges();
                return res;
            });
        }

        public Task<int> DelFirstKind(short ffkid)
        {
            return Task.Run(() =>
            {
                config_file_first_kind? fk = db.config_file_first_kinds.Find(ffkid);
                db.config_file_first_kinds.Remove(fk);
                return db.SaveChanges();
            });
        }
    }
}
